from tools_algorithm import *


class Solution:
    def distinctNames(self, ideas: List[str]) -> int:
        s = set(ideas)
        cnt = [[0] * 26 for _ in range(26)]

        def f(w):
            return ord(w) - ord("a")

        ans = 0
        for idea in ideas:
            c = idea[0]
            r = idea[1::]
            for w in ascii_lowercase:
                if w != c and (w + r) not in s:
                    ans += cnt[f(w)][f(c)]
                    cnt[f(c)][f(w)] += 1

        return ans << 1


def randomString(size):
    c = []
    for _ in range(size):
        c.append(chr(random.randint(0, 25) + ord("a")))
    return "".join(c)


c = []
for _ in range(3):
    r = randomString(9)
    c.append(r)
    if random.randint(0, 1) == 1:
        for i in range(random.randint(0, 10)):
            c.append(chr(i + ord("a")) + r)

print(c)
